﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using GBIT.Web;
using WebComponents;
using WebComponents.Data;
using System.Collections.Generic;

public partial class NhaSanXuatList : UserControlBase {
  protected void Page_Load(object sender, EventArgs e) {
    this.AddModule = "NhaSanXuat/ThemNhaSanXuat.ascx";
    this.AddEnabled = true;

    this.Title = "Nhà sản xuất";
    if (!Page.IsPostBack)
      LoadData();
    this.EditEnabled = true;
    this.DeleteEnabled = true;
  }
  protected override void OnDeleteRecord() {
    foreach (GridViewRow row in grvFileInfo.Rows) {
      if (((HtmlInputCheckBox)row.FindControl("chkSelect")).Checked) {
        ManufacturerController.Delete(ConvertType.ToInt(((HtmlInputCheckBox)row.FindControl("chkSelect")).Attributes["title"].ToString()));
      }
    }
    LoadData();
  }
  private void LoadData() {
    var list = ManufacturerController.List();
    grvFileInfo.DataSource = list;
    grvFileInfo.DataBind();
    if (list.Count == 0) {
      this.EditEnabled = false;
      this.DeleteEnabled = false;
    } else {
      this.EditEnabled = true;
      this.DeleteEnabled = true;
    }
  }
  protected void grvFileInfo_PageIndexChanging(object sender, GridViewPageEventArgs e) {
    List<ManufacturerInfo> files = ManufacturerController.List();
    grvFileInfo.PageIndex = e.NewPageIndex;
    grvFileInfo.DataSource = files;
    grvFileInfo.DataBind();
  }
}
